/*
    GameMenu extends JMenuBar implements ActionListener implements ItemListener
        :Standard menubar that would be visible when playing the game
        :It is part of the GameView.
        Attributes
        Methods
            GameMenu()
                :this is the constructor for the component
                :this instantiates and sets up the different menus and menu items
                :this adds the various menus and menu items to itself and each other respectively
            actionPerformed(ActionEvent)
                :overridden as part of ActionListener
                :used when a standard menu item is selected
            itemStateChanged(ItemEvent)
                :overridden as part of ItemListener
                :used when a unique menu item (such as checkbox) is changed
*/

//This is the game menu class
//this class serves as the menu bar that is accessable while playing the game
/*The menu bar will include a number of functional options such as...
	File
		New Game: 
			prompts the user if they are sure about discarding the current game
			this should tell GameBoard to clear the temporary game data 
				and reload the gameview screen
		Load Game: 
			prompts the user if they are sure about discarding the current game
			in build 1, this should do nothing
			in future builds, this should tell GameBoard to clear the temporary game data 
				and load the gameload screen
		Save Game:
			in build 1, this should do nothing
			in future builds, this should tell UIController to save
		Close Game:
			prompts the user if they are sure about discarding the current game
			this should tell GameBoard to clear the temporary game data 
				and load the mainview screen
		Exit:
			prompts the user if they are sure about discarding the current game
			this should tell the UIController to exit properly
	View
		Side by Side:
			this should tell the GameBoard to change to side view
		Back to Back:
			this should tell the GameBoard to change to back view
		Customize:
			this should tell the GameBoard to display the customize screen
	Help
		Tutorial:
			in build 1, this should do nothing
		Help Topics:
			in build 1, this should do nothing
		About:
			in build 1, this should do nothing


*/

//import anything we need
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator;
import javax.swing.KeyStroke;
import javax.swing.ButtonGroup;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.Dimension;


public class GameMenu extends JMenuBar implements ActionListener {
	
	//declare any objects we would like to have references to after the constructor exits
	private JMenu filemenu;
	private JMenuItem newgameitem;
	private JMenuItem loadgameitem;
	private JMenuItem savegameitem;
	private JMenuItem closegameitem;
	private JMenuItem exitgameitem;
	private JMenu viewmenu;
	private JRadioButtonMenuItem sideviewitem;
	private JRadioButtonMenuItem backviewitem;
	private JMenuItem customizeviewitem;
	private JMenu helpmenu;
	private JMenuItem tutorialhelpitem;
	private JMenuItem topicshelpitem;
	private JMenuItem abouthelpitem;
	
	//our big constructor
	public GameMenu() {
		
		//call our ancestor
		super();
		
		//setup our file menu items
			//setup our New Game menu item
				//use N as the mnemonic
				//use Ctrl-N as the accelerator
				newgameitem = new JMenuItem("New Game...");
				newgameitem.setMnemonic(KeyEvent.VK_N);
				newgameitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
				newgameitem.addActionListener(this);
			//setup our Load Game menu item
				//use L as the mnemonic
				//use Ctrl-O as the accelerator
				loadgameitem = new JMenuItem("Load Game...");
				loadgameitem.setMnemonic(KeyEvent.VK_L);
				loadgameitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
				loadgameitem.addActionListener(this);
				//disabled in Build 1
				loadgameitem.setEnabled(true);
			//setup our Save Game menu item
				//use S as the mnemonic
				//use Ctrl-S as the accelerator
				savegameitem = new JMenuItem("Save Game...");
				savegameitem.setMnemonic(KeyEvent.VK_S);
				savegameitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
				savegameitem.addActionListener(this);
				//disabled in Build 1
				savegameitem.setEnabled(true);
			//setup our Close Game menu item
				//use C as the mnemonic
				//use Ctrl-F4 as the accelerator
				closegameitem = new JMenuItem("Close Game...");
				closegameitem.setMnemonic(KeyEvent.VK_C);
				closegameitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.CTRL_MASK));
				closegameitem.addActionListener(this);
			//setup our Exit menu item
				//use E as the mnemonic
				//use Alt-F4 as the accelerator
				exitgameitem = new JMenuItem("Exit");
				exitgameitem.setMnemonic(KeyEvent.VK_X);
				exitgameitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
				exitgameitem.addActionListener(this);
			//setup our file menu
			//use F as the mnemonic
			filemenu = new JMenu("File");
			filemenu.setMnemonic(KeyEvent.VK_F);
			//add our items to the file menu
			filemenu.add(newgameitem);
			filemenu.add(loadgameitem);
			filemenu.add(savegameitem);
			filemenu.add(closegameitem);
			filemenu.add(new JSeparator(JSeparator.HORIZONTAL));
			filemenu.add(exitgameitem);
			
		//setup our view menu items
			//setup our Side by Side view menu item
				//use D as the mnemonic
				//use Ctrl-D as the accelerator
				//have selected by default
				sideviewitem = new JRadioButtonMenuItem("Side - by - Side", true);
				sideviewitem.setMnemonic(KeyEvent.VK_D);
				sideviewitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));
				sideviewitem.addActionListener(this);
			//setup our Back to Back view menu item
				//use B as the mnemonic
				//use Ctrl-B as the accelerator
				//have deselected by default
				backviewitem = new JRadioButtonMenuItem("Back - to - Back", false);
				backviewitem.setMnemonic(KeyEvent.VK_B);
				backviewitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK));
				backviewitem.addActionListener(this);
			//setup our Customize view menu item
				//use U as the mnemonic
				//use Ctrl-Shift-U as the accelerator
				customizeviewitem = new JMenuItem("Customize...");
				customizeviewitem.setMnemonic(KeyEvent.VK_U);
				customizeviewitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
				customizeviewitem.addActionListener(this);
				//disabled in Build 1
				customizeviewitem.setEnabled(false);
			//setup our view menu
			//use V as the mnemonic
			viewmenu = new JMenu("View");
			viewmenu.setMnemonic(KeyEvent.VK_V);
			//add our items to the view menu
			//need a temporary Button Group so that radio buttons 
			//  will play nicely with one another
			ButtonGroup tempgroup = new ButtonGroup();
			tempgroup.add(sideviewitem);
			tempgroup.add(backviewitem);
			viewmenu.add(sideviewitem);
			viewmenu.add(backviewitem);
			viewmenu.add(new JSeparator(JSeparator.HORIZONTAL));
			viewmenu.add(customizeviewitem);
			
		//setup our help menu items
			//setup our Tutorial menu item
				//use T as the mnemonic
				//use Ctrl-Shift-T as the accelerator
				tutorialhelpitem = new JMenuItem("Tutorial...");
				tutorialhelpitem.setMnemonic(KeyEvent.VK_T);
				tutorialhelpitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
				tutorialhelpitem.addActionListener(this);
				//diabled in Build 1
				tutorialhelpitem.setEnabled(false);
			//setup our Help Topics menu item
				//use H as the mnemonic
				//use Ctrl-H as the accelerator
				topicshelpitem = new JMenuItem("Help Topics");
				topicshelpitem.setMnemonic(KeyEvent.VK_H);
				topicshelpitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.CTRL_MASK));
				topicshelpitem.addActionListener(this);
				//disabled in Build 1
				topicshelpitem.setEnabled(false);
			//setup our About menu item
				//use A as the mnemonic
				//use Ctrl-Shift-A as the accelerator
				abouthelpitem = new JMenuItem("About...");
				abouthelpitem.setMnemonic(KeyEvent.VK_A);
				abouthelpitem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK + ActionEvent.SHIFT_MASK));
				abouthelpitem.addActionListener(this);
				//disabled in Build 1
				abouthelpitem.setEnabled(false);
			//setup our file menu
			//use H as the mnemonic
			helpmenu = new JMenu("Help");
			helpmenu.setMnemonic(KeyEvent.VK_H);
			//add our items to the help menu
			helpmenu.add(tutorialhelpitem);
			helpmenu.add(topicshelpitem);
			helpmenu.add(abouthelpitem);
		
		//add our menus to our menu bar
		this.add(filemenu);
		this.add(viewmenu);
		this.add(helpmenu);
		
		//set a reasonable size to match the ratio of our splash image
		this.setPreferredSize(new Dimension(500, 25));
		
		//setup visibilities
		this.setVisible(true);
		this.setOpaque(true);
		
	}
	
	//special method to select the board view
	public void selectBoardView(String view) {
		
		//check what view we want
		if (view.equals("Back")){
			backviewitem.setSelected(true);
		}else{
			sideviewitem.setSelected(true);
		}
		
	}
	
	//our overridden method as part of ActionListener
	public void actionPerformed(ActionEvent EVE) {
		
		//declare any temporary vars here
		boolean response = false;
		
		//we need to determine who is linked to this action
		Object tmpobj = EVE.getSource();
		
		//compare against known objects
		if (tmpobj.equals(newgameitem)){
			//response = GameView.gameboard.newGame();
			response = ((GameView)UIController.grabState("GameView")).gameboard.newGame();
			if (response){
				UIController.changeState("GameView");
			}
		}else if (tmpobj.equals(loadgameitem)){
			//response = GameView.gameboard.loadGame();
			response = ((GameView)UIController.grabState("GameView")).gameboard.loadGame();
			if (response){
				UIController.changeState("GameLoad");
			}
		}else if (tmpobj.equals(savegameitem)){
			//GameView.gameboard.saveGame();
			((GameView)UIController.grabState("GameView")).gameboard.saveGame();
		}else if (tmpobj.equals(closegameitem)){
			//response = GameView.gameboard.closeGame();
			response = ((GameView)UIController.grabState("GameView")).gameboard.closeGame();
			if (response){
				UIController.changeState("MainView");
			}
		}else if (tmpobj.equals(exitgameitem)){
			//response = GameView.gameboard.exitGame();
			response = ((GameView)UIController.grabState("GameView")).gameboard.exitGame();
			if (response){
				UIController.exit();
			}
		}else if (tmpobj.equals(sideviewitem)){
			//GameView.gameboard.viewSidebySide();
			((GameView)UIController.grabState("GameView")).gameboard.viewSidebySide();
		}else if (tmpobj.equals(backviewitem)){
			//GameView.gameboard.viewBacktoBack();
			((GameView)UIController.grabState("GameView")).gameboard.viewBacktoBack();
		}else if (tmpobj.equals(customizeviewitem)){
			//do nothing in build 1
		}else if (tmpobj.equals(tutorialhelpitem)){
			//do nothing in build 1
		}else if (tmpobj.equals(topicshelpitem)){
			//do nothing in build 1
		}else if (tmpobj.equals(abouthelpitem)){
			//do nothing in build 1
		}
		
	}
	
}